package com.ruoyi.common.core.enums;

import java.util.Objects;

/**
 * 币种枚举，更新本枚举之后，需要同步检查维护{@code CountryEnum}枚举
 * 中与国家/地区的对应关系。
 *
 * @see com.fkmalls.cbec.common.core.enums.CountryEnum
 */
public enum CurrencyEnum {
    /**
     * 币种
     */
    CNY("CNY","RMB","人民币","￥"),
    USD("USD","Dollar","美元","$"),
    EUR("EUR","Euro","欧元","€"),
    HKD("HKD","Hong Kong Dollars","港元","HKD"),
    MOP("MOP","Macau Pataca","澳门币","MOP"),
    TWD("TWD","New Taiwan dollar","新台币","NT$"),
    JPY("JPY","Japanese yen","日元","¥"),
    KRW("KRW","South Korean won","韩元","₩"),
    THB("THB","Thai baht","泰铢","฿"),
    VND("VND","Vietnamese đồng","越南盾","₫"),
    SGD("SGD","Singapore Dollar","新加坡元","S$"),
    MYR("MYR","Malaysian Ringgit","马来西亚令吉","RM"),
    LAK("LAK","Lao Kip","老挝基普","₭"),
    INR("INR","Indian Rupee","印度卢比","Rs"),
    PHP("PHP","Piso ng Pilipinas","菲律宾比索","₱"),
    MMK("MMK","Myanmar kyat","缅元","K"),
    BND("BND","Brunei dollar","文莱元","B$"),
    KHR("KHR","Riel","柬埔寨瑞尔","CR"),
    MNT("MNT","Mongolian tögrög","图格里克","₮"),
    KPW("KPW","朝鲜圆","朝鲜圆","₩"),
    NPR("NPR","Nepalese rupee","尼泊尔卢比","Rs"),
    CNH("CNH","Offshore RMB","离岸人民币","￥"),
    BTN("BTN","Bhutanese ngultrum","不丹努尔特鲁姆","Nu."),
    AUD("AUD","Australian Dollar","澳大利亚元","A$"),

    CAD("CAD","Canadian Dollar","加拿大元","C$"),

    CHF("CHF","Swiss Francs","瑞士法郎","₣"),

    DKK("DKK","Danish Kroners","丹麦克朗","DKr"),

    NOK("NOK","Norwegian Kroners","挪威克朗","N.Kr."),

   // NTD("NTD","New Taiwan Dollar","新台币","NT$"),

    NZD("NZD","New Zealand Dollars","新西兰币","NZ$"),

    PKR("PKR","Pakistan Rupees","巴基斯坦卢比","P.Re."),

    SEK("SEK","Swedish Kroners","瑞典克朗","Kr"),

    ZAR("ZAR","C. South African Rand","南非兰特","R."),
    ;

    private final String code;
    private final String nameEn;
    private final String nameCn;
    private final String symbol;

    CurrencyEnum(String code, String nameEn, String nameCn, String symbol) {
        this.code = code;
        this.nameEn = nameEn;
        this.nameCn = nameCn;
        this.symbol = symbol;
    }

    public String getCode() {
        return code;
    }

    public String getNameEn() {
        return nameEn;
    }

    public String getNameCn() {
        return nameCn;
    }

    public String getSymbol() {
        return symbol;
    }


    public static CurrencyEnum parseByCode(String code) {
        for (CurrencyEnum item : CurrencyEnum.values()) {
            if (item.getCode().equals(code)) {
                return item;
            }
        }
        return null;
    }



    public static String getNameEnByCode(String code) {
        for (CurrencyEnum item : CurrencyEnum.values()) {
            if (item.getCode().equals(code)) {
                return item.getNameEn();
            }
        }
        return "";
    }

    public static String getNameCnByCode(String code) {
        for (CurrencyEnum item : CurrencyEnum.values()) {
            if (item.getCode().equals(code)) {
                return item.getNameCn();
            }
        }
        return "";
    }

    public static String getSymbolByCode(String code) {
        for (CurrencyEnum item : CurrencyEnum.values()) {
            if (item.getCode().equals(code)) {
                return item.getSymbol();
            }
        }
        return "";
    }

    public static CurrencyEnum parseByCurTypeCode(Integer curTypeCode) {
        CurTypeEnum curTypeEnum = CurTypeEnum.parseByCode(curTypeCode);
        switch (curTypeEnum) {
            case RMB:
                return CurrencyEnum.CNY;
            case HONGKONG_DOLLAR:
                return CurrencyEnum.HKD;
            case DOLLAR:
                return CurrencyEnum.USD;
            case dollar_a:
                return CurrencyEnum.AUD;
            case EUR:
                return CurrencyEnum.EUR;
            case JPY:
                return CurrencyEnum.JPY;
            default:

        }

        return null;
    }

    public static String getCodeByCurTypeCode(Integer curTypeCode) {
        CurrencyEnum currencyEnum = parseByCurTypeCode(curTypeCode);
        return Objects.isNull(currencyEnum) ? null : currencyEnum.getCode();
    }
}
